<?php

/**
 * Description of Comments
 *
 * @author Suraj
 */
class Model_Comments extends Zend_Db_Table{
    protected $_name="Comments";

    //to fetch all the comments relates to a post id
    function getComment($postid) {
        $com=$this->fetchAll('post_id ='.$postid);
        return $com->toArray();
    }

    function oneComment($id) {
        $this->comm=$this->fetchRow('id ='.$id);
        return $this->comm->toArray();
    }
    
    //Create comment.
    function newComment ($crtComnt){
        $query=array (
            'post_id'=>$crtComnt['post_id'],
            'Description'=>$crtComnt['Description'],
            'Name'=>$crtComnt['Name'],
            'Email'=>$crtComnt['Email'],
            'Webpage'=>$crtComnt['Webpage'],
            'Postedon'=>new Zend_Db_Expr('now()')
        );
        return $this->insert($query);
    }


    //update comment.
    function updateComment ($updComnt){
        $query=array (
            'Description'=>$updComnt['Description'],
            'Name'=>$updComnt['Name'],
            'Email'=>$updComnt['Email'],
            'Webpage'=>$updComnt['Webpage']
        );
        return $this->update($query, 'id ='.$updComnt['id'] );
    }

    // delete comment according to its id.
    function deleteComment($cmtid) {
        return $this->delete('id ='.$cmtid);
    }
}
?>
